//
//  DatePicker.m
//  iHedron
//
//  Created by George Radev on 2011-08-13.
//  Copyright 2011 I Me Mine. All rights reserved.
//

#import "DatePicker.h"
#import "HedronCore.h"


@implementation DatePicker
@synthesize date, datePicker;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	UIBarButtonItem* rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Установи" 
									style:UIBarButtonItemStylePlain target:self action:@selector(doUpdateDate)];
	self.navigationItem.rightBarButtonItem = rightButton;
	[rightButton release];
	
	self.title = @"Дата";
	
	if(*date){
		[datePicker setDate: [NSDate dateWithTimeIntervalSince1970:*date]];
	}
}

-(void)doUpdateDate {
	NSDate* selectedDate = datePicker.date;
	long d = [selectedDate timeIntervalSince1970];
	d = [HedronCore dateFlat:d];
	*date = d;
	[selectedDate release];
	[self.navigationController popViewControllerAnimated:TRUE];	
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
